package com.live.activity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.live.adapter.LiveTopicSA;
import com.live.adapter.LiveVideoSA;
import com.live.common.Constant;
import com.live.common.LiveImageHelper;
import com.live.task.LiveDetail;
import com.live.task.LiveFavor;
import com.live.task.LiveMemberStats;
import com.live.task.LiveScore;
import com.live.task.LiveScoreCache;
import com.live.task.LiveTeamStats;
import com.live.task.LiveTopic;
import com.live.task.LiveVideo;

public class LiveDetailActivity extends LiveBaseActivity {

	private Bundle bundle;

	private LiveImageHelper image;

	protected static final int UPDATE_TEXT = 0;

	private List<Map<String, Object>> liveVideoList = new ArrayList<Map<String, Object>>();
	private LiveVideoSA liveVideoAdapter;

	private List<Map<String, Object>> liveTopicList = new ArrayList<Map<String, Object>>();
	private LiveTopicSA topicSA;

	private LiveTopic reviewTask = null;
	private LiveTeamStats teamStatsTask = null;
	private LiveMemberStats memberStatsTask = null;
	private LiveFavor favorTask = null;

	public boolean refresh = true;

	private Timer mTimer;
	private TimerTask mTimerTask;
	private Handler mHandler;

	private TextView matchName = null;
	private TextView homeTeam = null;
	private TextView homeTeamScore = null;
	private ImageView homeTeamPic = null;
	private TextView homeFavor = null;
	private TextView visitTeam = null;
	private TextView visitTeamScore = null;
	private ImageView visitTeamPic = null;
	private TextView visitFavor = null;
	private TextView matchStatus = null;
	private TextView matchEventStatus = null;
	private String matchId = null;
	private String matchCategory = null;
	private String matchRecord = null;
	private String visitTeamName = null;
	private String homeTeamName = null;

	private Dialog favorDialog = null;

	private LinearLayout viewMatch = null;
	private ListView matchLiveLV = null;
	private TextView matchLiveMsg = null;
	// private TextView matchLiveLVWaitMsg = null;
	private RelativeLayout viewMatchBbs = null;
	private ListView matchTopicLV = null;
	private LinearLayout sendMsgArea = null;
	private LinearLayout userLoginArea = null;
	private Button sendMsgBtn = null;
	private ScrollView viewTeamStstsB = null;
	private ScrollView viewTeamStstsF = null;
	private TextView viewTeamStstsMsg = null;
	private ScrollView viewMemberStatsB = null;
	private ScrollView viewMemberStatsF = null;
	private TextView viewMemberStatsMsg = null;
	private ListView viewMatchVideo = null;
	private TextView viewMatchVideoMsg = null;
	public int setTimeout = 60000;

	private View liveFoot;
	private int page = 0;
	private int lastIndex = 0;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// 网络连接判断
		if (netIsOk) {

			setContentView(R.layout.live_detail);

			/* 获取Intent中的Bundle对象 */
			bundle = this.getIntent().getExtras();

			matchId = bundle.getString("matchId");

			/* 获取Bundle中的数据，注意类型和key */
			homeTeam = (TextView) findViewById(R.id.homeTeam);
			homeTeamScore = (TextView) findViewById(R.id.homeTeamScore);
			homeTeamPic = (ImageView) findViewById(R.id.homeTeamPic);

			homeFavor = (TextView) findViewById(R.id.homeFavor);
			visitTeam = (TextView) findViewById(R.id.visitTeam);
			visitTeamScore = (TextView) findViewById(R.id.visitTeamScore);
			visitTeamPic = (ImageView) findViewById(R.id.visitTeamPic);

			visitFavor = (TextView) findViewById(R.id.visitFavor);
			matchStatus = (TextView) findViewById(R.id.matchStatus);
			matchStatus.setText(bundle.getString("matchStatus"));

			matchEventStatus = (TextView) findViewById(R.id.matchEventStatus);
			matchEventStatus.setText(bundle.getString("matchStatus"));

			matchName = (TextView) findViewById(R.id.matchName);
			matchName.setText(bundle.getString("matchName"));

			homeTeam.setText(bundle.getString("homeTeam"));
			homeTeamScore.setText(bundle.getString("homeTeamScore"));

			image = new LiveImageHelper(homeTeamPic);
			image.execute(bundle.getString("homeTeamPic"));

			visitTeam.setText(bundle.getString("visitTeam"));
			visitTeamScore.setText(bundle.getString("visitTeamScore"));

			image = new LiveImageHelper(visitTeamPic);
			image.execute(bundle.getString("visitTeamPic"));

			matchCategory = bundle.getString("matchCategory");
			matchRecord = bundle.getString("matchRecord");

			// 设置球队名称，为粉丝支持提供KEY
			homeTeamName = bundle.getString("homeTeamName");
			visitTeamName = bundle.getString("visitTeamName");

			homeFavor.setText(Constant.NUM_ZERO);
			visitFavor.setText(Constant.NUM_ZERO);
			TextView favor = (TextView) findViewById(R.id.favor);
			favor.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					favorDialog = new Dialog(context, R.style.dialog);
					// 去掉标题
					favorDialog.setContentView(R.layout.live_favor);
					favorDialog.setCanceledOnTouchOutside(true);
					// 为获取屏幕宽、高
					Display d = getWindowManager().getDefaultDisplay();
					// 获取对话框当前的参数值
					LayoutParams p = favorDialog.getWindow().getAttributes();
					// 宽度设置
					p.width = (int) (d.getWidth() * 0.95);
					// 设置生效
					favorDialog.getWindow().setAttributes(p);
					// 显示对话框
					favorDialog.show();

					ImageView homeTeamPic = (ImageView) favorDialog.findViewById(R.id.homeTeamPic);
					ImageView visitTeamPic = (ImageView) favorDialog.findViewById(R.id.visitTeamPic);

					TextView favorHomeTeam = (TextView) favorDialog.findViewById(R.id.homeTeam);
					favorHomeTeam.setText(bundle.getString("homeTeam"));
					TextView favorVisitTeam = (TextView) favorDialog.findViewById(R.id.visitTeam);
					favorVisitTeam.setText(bundle.getString("visitTeam"));

					// 设置球队头像
					image = new LiveImageHelper(homeTeamPic);
					image.execute(bundle.getString("homeTeamPic"));
					image = new LiveImageHelper(visitTeamPic);
					image.execute(bundle.getString("visitTeamPic"));

					homeTeamPic.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View v) {
							favorTask = new LiveFavor(context, homeTeamName, homeFavor, visitFavor);
							favorTask.execute(bundle);
							favorDialog.dismiss();
						}
					});

					visitTeamPic.setOnClickListener(new View.OnClickListener() {
						@Override
						public void onClick(View v) {
							favorTask = new LiveFavor(context, visitTeamName, homeFavor, visitFavor);
							favorTask.execute(bundle);
							favorDialog.dismiss();
						}
					});
				}
			});

			// 设置刷新时间
			if (matchCategory.equals("1")) {
				// 篮球
				setTimeout = 10000;
			} else if (matchCategory.equals("2") || matchCategory.equals("3")) {
				// 足球
				setTimeout = 15000;
			} else if (matchCategory.equals("6")) {
				// 网球
				setTimeout = 15000;
			} else {
				// 其他
				setTimeout = 15000;
			}

			LinearLayout viewMatchInfo = (LinearLayout) findViewById(R.id.view_match_info);
			LinearLayout viewMatchEventInfo = (LinearLayout) findViewById(R.id.view_match_event_info);
			LinearLayout viewMatchHomeInfo = (LinearLayout) findViewById(R.id.view_match_home_info);
			LinearLayout viewMatchScoreInfo = (LinearLayout) findViewById(R.id.view_match_score_info);
			LinearLayout viewMatchVisitInfo = (LinearLayout) findViewById(R.id.view_match_visit_info);

			viewMatchInfo.removeAllViews();
			if ("".equals(homeTeam.getText()) && "".equals(visitTeam.getText())) {
				viewMatchInfo.addView(viewMatchEventInfo);
			} else {
				viewMatchInfo.addView(viewMatchHomeInfo);
				viewMatchInfo.addView(viewMatchScoreInfo);
				viewMatchInfo.addView(viewMatchVisitInfo);
			}

			// 添加“读取更多按钮”
			liveFoot = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
					R.layout.live_foot, null, false);

			viewMatch = (LinearLayout) findViewById(R.id.view_match);
			matchLiveLV = (ListView) findViewById(R.id.view_match_live);
			matchLiveMsg = (TextView) findViewById(R.id.view_match_live_msg);
			// matchLiveLVWaitMsg = (TextView)
			// findViewById(R.id.view_match_live_wait_msg);
			viewMatchBbs = (RelativeLayout) findViewById(R.id.view_match_bbs);
			matchTopicLV = (ListView) findViewById(R.id.reviewList);
			sendMsgArea = (LinearLayout) findViewById(R.id.sendMsgArea);
			userLoginArea = (LinearLayout) findViewById(R.id.userLoginArea);
			sendMsgBtn = (Button) findViewById(R.id.sendMsgBtn);
			viewTeamStstsB = (ScrollView) findViewById(R.id.view_team_stats_b);
			viewTeamStstsF = (ScrollView) findViewById(R.id.view_team_stats_f);
			viewTeamStstsMsg = (TextView) findViewById(R.id.view_team_stats_msg);
			viewMemberStatsB = (ScrollView) findViewById(R.id.view_member_stats_b);
			viewMemberStatsF = (ScrollView) findViewById(R.id.view_member_stats_f);
			viewMemberStatsMsg = (TextView) findViewById(R.id.view_member_stats_msg);
			viewMatchVideo = (ListView) findViewById(R.id.view_match_video);
			viewMatchVideoMsg = (TextView) findViewById(R.id.view_match_video_msg);
			viewMatch.removeAllViews();

			// 文字直播
			TextView matchLive = (TextView) findViewById(R.id.matchLive);
			matchLive.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					changeTabInit(R.id.matchLiveLine);

					if (matchRecord != null) {
						viewMatch.addView(matchLiveLV);
					} else {
						viewMatch.addView(matchLiveMsg);
					}
				}
			});

			// 粉丝交流
			topicSA = new LiveTopicSA(context, liveTopicList, R.layout.topic_list, new String[] {}, new int[] {},
					store.getString("id", null));
			matchTopicLV.setAdapter(topicSA);
			matchTopicLV.setOnItemClickListener(new OnItemClickListener() {

				// 从当前画面到比分明细画面跳转，并传值。

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
					Map<String, Object> obj = liveTopicList.get(arg2);

					String uId = store.getString("id", null);

					// 如果用户已经登录，且不是本人。
					if (uId != null && !uId.equals((String) obj.get("uId"))) {
						// 发表回复
						Intent intent = new Intent();
						intent.setClass(context, LiveReplayActivity.class);
						Bundle bundle = new Bundle();
						bundle.putString("matchId", matchId);
						bundle.putString("replayId", (String) obj.get("id"));
						bundle.putString("userName", (String) obj.get("userId"));
						bundle.putString("userId", uId);
						bundle.putString("atUserId", (String) obj.get("uId"));
						bundle.putString("topicTitle", "#" + matchName.getText() + " " + homeTeam.getText() + "VS"
								+ visitTeam.getText() + "#");
						bundle.putString("topicContent", (String) obj.get("content"));
						intent.putExtras(bundle);
						startActivityForResult(intent, Constant.REQUEST_CODE);
					}
				}
			});
			matchTopicLV.setOnScrollListener(new OnScrollListener() {

				@Override
				public void onScrollStateChanged(AbsListView view, int scrollState) {
					if (scrollState == OnScrollListener.SCROLL_STATE_IDLE && lastIndex == topicSA.getCount()) {
						page = page + 1;
						Bundle bundle = new Bundle();
						bundle.putString("matchId", matchId);
						bundle.putString("uId", store.getString("id", null));
						bundle.putInt("page", page);
						reviewTask = new LiveTopic(context, liveTopicList, topicSA, viewMatch, Constant.ACTION_SELECT,
								matchTopicLV, liveFoot);
						reviewTask.execute(bundle);
					}
				}

				@Override
				public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

					// 计算最后可见条目的索引
					lastIndex = firstVisibleItem + visibleItemCount - 1;
				}
			});

			TextView matchBbs = (TextView) findViewById(R.id.matchBbs);
			matchBbs.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					changeTabInit(R.id.matchBbsLine);

					viewMatch.addView(viewMatchBbs);
					Bundle bundle = new Bundle();
					bundle.putString("matchId", matchId);
					bundle.putString("uId", store.getString("id", null));
					reviewTask = new LiveTopic(context, liveTopicList, topicSA, viewMatch, Constant.ACTION_SELECT,
							matchTopicLV, liveFoot);
					reviewTask.execute(bundle);

					// 如果用户已经登录，则可以发表评论
					store = getSharedPreferences(Constant.PREFS_NAME, MODE_PRIVATE);
					if (store.getString("id", null) != null) {
						userStatus = Constant.LOGIN;
						sendMsgArea.removeView(userLoginArea);
						// 发表/回复评论按钮
						sendMsgBtn.setOnClickListener(new View.OnClickListener() {
							public void onClick(View v) {

								// 发表/回复评论页
								Intent intent = new Intent();
								intent.setClass(context, LiveTopicActivity.class);
								Bundle bundle = new Bundle();
								bundle.putString("matchId", matchId);
								bundle.putString("userId", store.getString("id", null));
								bundle.putString("topicTitle", "#" + matchName.getText() + " " + homeTeam.getText()
										+ "VS" + visitTeam.getText() + "#");
								intent.putExtras(bundle);
								startActivityForResult(intent, Constant.REQUEST_CODE);

							}
						});
					} else {
						userStatus = Constant.LOGOUT;
						sendMsgArea.removeView(sendMsgBtn);

						Button loginBtn = (Button) findViewById(R.id.loginBtn);
						loginBtn.setOnClickListener(new ImageView.OnClickListener() {
							@Override
							public void onClick(View v) {
								Intent intent = new Intent();
								intent.setClass(context, LiveUserLoginActivity.class);
								startActivityForResult(intent, Constant.REQUEST_CODE);
							}
						});

						Button registBtn = (Button) findViewById(R.id.registBtn);
						registBtn.setOnClickListener(new ImageView.OnClickListener() {
							@Override
							public void onClick(View v) {
								Intent intent = new Intent();
								intent.setClass(context, LiveUserRegistActivity.class);
								startActivityForResult(intent, Constant.REQUEST_CODE);
							}
						});
					}
				}
			});

			// 球队统计
			TextView matchTeamStats = (TextView) findViewById(R.id.matchTeamStats);
			matchTeamStats.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					changeTabInit(R.id.matchTeamStatsLine);

					// 只有篮球、足球比赛才有球队统计
					if ((Integer.parseInt(matchCategory) == 1 || Integer.parseInt(matchCategory) == 2 || Integer
							.parseInt(matchCategory) == 3)
							&& matchRecord != null
							&& !"".equals(homeTeam.getText())
							&& !"".equals(visitTeam.getText())) {

						if ("1".equals(matchCategory)) {
							viewMatch.addView(viewTeamStstsB);
							teamStatsTask = new LiveTeamStats(viewTeamStstsB, viewMatch);
						} else if ("2".equals(matchCategory) || "3".equals(matchCategory)) {
							viewMatch.addView(viewTeamStstsF);
							teamStatsTask = new LiveTeamStats(viewTeamStstsF, viewMatch);
						}

						teamStatsTask.execute(bundle);
					} else {
						viewMatch.addView(viewTeamStstsMsg);
					}
				}
			});

			// 球员统计
			TextView matchMemberStats = (TextView) findViewById(R.id.matchMemberStats);
			matchMemberStats.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {

					changeTabInit(R.id.matchMemberStatsLine);

					// 只有篮球、足球比赛才有球员统计
					if ((Integer.parseInt(matchCategory) == 1 || Integer.parseInt(matchCategory) == 2 || Integer
							.parseInt(matchCategory) == 3)
							&& matchRecord != null
							&& !"".equals(homeTeam.getText())
							&& !"".equals(visitTeam.getText())) {

						if ("1".equals(matchCategory)) {
							viewMatch.addView(viewMemberStatsB);
							memberStatsTask = new LiveMemberStats(context, viewMatch);
						} else if ("2".equals(matchCategory) || "3".equals(matchCategory)) {
							viewMatch.addView(viewMemberStatsF);
							memberStatsTask = new LiveMemberStats(context, viewMatch);
						}

						memberStatsTask.execute(bundle);
					} else {
						viewMatch.addView(viewMemberStatsMsg);
					}
				}
			});

			// 精彩视频
			liveVideoAdapter = new LiveVideoSA(context, liveVideoList, R.layout.video_list, new String[] {
					"videoTitle", "videoLength", "videoWatch", "videoTime" }, new int[] { R.id.videoTitle,
					R.id.videoLength, R.id.videoWatch, R.id.videoTime }, viewMatchVideo);
			viewMatchVideo.setAdapter(liveVideoAdapter);
			viewMatchVideo.setOnItemClickListener(new OnItemClickListener() {

				// 从当前画面到比分明细画面跳转，并传值。
				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

					Map<String, Object> video = liveVideoList.get(arg2);

					Intent intent = new Intent();

					intent.setClass(context, LiveVideoActivity.class);

					// 实例化 Bundle，设置需要传递的参数
					Bundle bundle = new Bundle();
					bundle.putString("videoId", video.get("videoId").toString());
					bundle.putString("videoUrl", video.get("videoUrl").toString());
					bundle.putString("videoTitle", video.get("videoTitle").toString());
					bundle.putString("videoCategory", video.get("videoCategory").toString());

					intent.putExtras(bundle);

					context.startActivity(intent);
				}
			});
			TextView matchVideo = (TextView) findViewById(R.id.matchVideo);
			matchVideo.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {

					changeTabInit(R.id.matchVideoLine);

					// 暂且只提供NBA比赛的精彩视频
					if ("1".equals(matchCategory) || "2".equals(matchCategory) || "3".equals(matchCategory)) {
						viewMatch.addView(viewMatchVideo);

						// 取得视频数据
						LiveVideo task = new LiveVideo(context, liveVideoList, liveVideoAdapter);
						task.execute(bundle);
					} else {
						viewMatch.addView(viewMatchVideoMsg);
					}
				}
			});

			// 判断是否提供文字直播
			if (matchRecord != null) {

				// 取得比分数据
				viewMatch.addView(matchLiveLV);

				// 从本机缓存中读取数据
				LiveScoreCache LiveScoreCacheTask = new LiveScoreCache(context, matchLiveLV, homeTeamScore,
						visitTeamScore, matchStatus);
				LiveScoreCacheTask.execute(bundle);

				// 从服务器中读取数据
				LiveScore liveScoreTask = new LiveScore(context, matchLiveLV, homeTeamScore, visitTeamScore,
						matchStatus, true);
				liveScoreTask.execute(bundle);

				// 定时刷新比分数据(只刷新有文字直播且未结束)
				if (!Constant.MATCH_STATUS_4.equals(bundle.getString("matchStatus")) && "●".equals(matchRecord)) {
					mHandler = new Handler() {
						@Override
						public void handleMessage(Message msg) {
							switch (msg.what) {
							case UPDATE_TEXT:
								LiveScore task = new LiveScore(context, matchLiveLV, homeTeamScore, visitTeamScore,
										matchStatus, false);
								task.execute(bundle);
								break;
							}
						}
					};

					mTimerTask = new TimerTask() {

						@Override
						public void run() {
							Log.d("AndroidTimerDemo", "timer");
							mHandler.sendEmptyMessage(UPDATE_TEXT);
						}
					};

					mTimer = new Timer();
					mTimer.schedule(mTimerTask, setTimeout, setTimeout); // 延时10000ms后执行，10000ms执行一次
				}
			} else {
				viewMatch.addView(matchLiveMsg);
			}

			// 取得支持数据
			favorTask = new LiveFavor(context, null, homeFavor, visitFavor);
			favorTask.execute(bundle);

			// 记录进出比赛详细页的信息
			LiveDetail detailTask = new LiveDetail(context, Constant.INPUT);
			detailTask.execute(bundle);
		}
	}

	private void changeTabInit(int tab) {
		// 隐藏下划线
		TextView matchLiveLine = (TextView) findViewById(R.id.matchLiveLine);
		matchLiveLine.setVisibility(Constant.INVISIBLE);
		TextView matchBbsLine = (TextView) findViewById(R.id.matchBbsLine);
		matchBbsLine.setVisibility(Constant.INVISIBLE);
		TextView matchTeamStatsLine = (TextView) findViewById(R.id.matchTeamStatsLine);
		matchTeamStatsLine.setVisibility(Constant.INVISIBLE);
		TextView matchMemberStatsLine = (TextView) findViewById(R.id.matchMemberStatsLine);
		matchMemberStatsLine.setVisibility(Constant.INVISIBLE);
		TextView matchVideoLine = (TextView) findViewById(R.id.matchVideoLine);
		matchVideoLine.setVisibility(Constant.INVISIBLE);

		TextView view = (TextView) findViewById(tab);
		view.setVisibility(Constant.VISIBLE);

		viewMatch.removeAllViews();
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == Constant.REQUEST_CODE) {
			if (resultCode != RESULT_CANCELED) {
				if (Constant.RELOAD.equals(data.getAction())) {
					// 如果用户已经登录，则可以发表评论
					store = getSharedPreferences(Constant.PREFS_NAME, MODE_PRIVATE);
					if (store.getString("id", null) != null) {
						userStatus = Constant.LOGIN;
						Bundle bundle = new Bundle();
						bundle.putString("matchId", matchId);
						bundle.putString("uId", store.getString("id", null));
						reviewTask = new LiveTopic(context, liveTopicList, topicSA, viewMatch, Constant.ACTION_SELECT,
								matchTopicLV, liveFoot);
						reviewTask.execute(bundle);

						if (findViewById(R.id.sendMsgBtn) == null) {
							sendMsgArea.removeView(userLoginArea);
							sendMsgArea.addView(sendMsgBtn);
							// 发表/回复评论按钮
							sendMsgBtn.setOnClickListener(new View.OnClickListener() {
								public void onClick(View v) {

									// 发表/回复评论页
									Intent intent = new Intent();
									intent.setClass(context, LiveTopicActivity.class);
									Bundle bundle = new Bundle();
									bundle.putString("matchId", matchId);
									bundle.putString("userId", store.getString("id", null));
									bundle.putString("topicTitle", "#" + matchName.getText() + " " + homeTeam.getText()
											+ "VS" + visitTeam.getText() + "#");
									intent.putExtras(bundle);
									startActivityForResult(intent, Constant.REQUEST_CODE);

								}
							});
						}
					}
				}
			}
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			if (mTimer != null) {
				mTimer.cancel();
			}

			// 记录退出比赛详细页的信息
			LiveDetail detailTask = new LiveDetail(context, Constant.OUTPUT);
			detailTask.execute(bundle);

			return super.onKeyDown(keyCode, event);
		}
		return super.onKeyDown(keyCode, event);
	}
}